package Operate;

import BookList.Book;
import BookList.Booklist;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-03-25
 * Time:10:10
 */
public class Deleteoperate implements IO{
    @Override
    public void work(Booklist book) {
        System.out.println("请输入删除的图书：");
        Scanner sc=new Scanner(System.in);
        String name=sc.nextLine();
        int t=0;
        for(int i=0;i< book.size;i++)
        {
            if(book.getBook(i).getName().equals(name))
            {
                for(int k=i+1;k<book.size;k++)
                {
                    Book fw = book.getBook(k);
                    book.setBook(i,fw);
                    i++;
                    t=1;

                }

            }
        }
        if(t==0)
            System.out.println("无此书");
        else
        {
            book.setBook(book.size,null);
            book.size--;
            System.out.println("删除成功");
        }
    }
}
